<template>
  <div>
    <!-- 页面基础模板 -->
    <base-header-footer
      :isShowContentTitle="false"
      :isShowBreadCrumb="false"
      :isShowArchived="false"
    >
      <!-- isShowTitle : 布尔值，是否显示当前页面标题组件-->
      <!-- isShowBreadCrumb : 布尔值，是否显示当前页面面包屑导航组件-->
      <!-- isShowArchived : 布尔值，是否显示当前页面归档组件-->
      <template slot="content-item">
        <!-- 内容插槽 -->
        <div class="app-search">
          <h2>站内搜索</h2>
          <div>
            <input
              type="text"
              name=""
              id=""
              placeholder="输入关键词搜索..."
              v-model="searchValue"
              @keydown.enter="handleSearch"
            />
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="handleSearch"
            ></el-button>
          </div>
        </div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="最近更新" name="first">
            <UserArticleList :articleList="articleList"></UserArticleList>
            <div class="toLoad" v-show="isShowToLoad">
              <p @click="handleToLoad">点击查看更多</p>
            </div>
          </el-tab-pane>
          <el-tab-pane label="同人&小画集" name="second">
            <UserArticleList :articleList="articleList"></UserArticleList>
            <div class="toLoad" v-show="isShowToLoad">
              <p @click="handleToLoad">点击查看更多</p>
            </div>
          </el-tab-pane>
          <el-tab-pane label="ACG角色图包" name="third">
            <UserArticleList :articleList="articleList"></UserArticleList>
            <div class="toLoad" v-show="isShowToLoad">
              <p @click="handleToLoad">点击查看更多</p>
            </div>
          </el-tab-pane>
          <el-tab-pane label="教程系列" name="fourth">
            <UserArticleList :articleList="articleList"></UserArticleList>
            <div class="toLoad" v-show="isShowToLoad">
              <p @click="handleToLoad">点击查看更多</p>
            </div>
          </el-tab-pane>
        </el-tabs>
      </template>
    </base-header-footer>
  </div>
</template>

<script>
import UserArticleList from "@/components/otherUser/ArticleList.vue";
import BaseHeaderFooter from "@/components/baseheaderfooter/BaseHeaderFooter.vue";
// import { getArticle } from "@/api/api";
export default {
  name: "",
  components: {
    UserArticleList,
    BaseHeaderFooter,
  },
  data() {
    return {
      searchValue: "",
      isShowToLoad: true,
      activeName: "first",
      articleList: [],
      currentPage: 1,
      totalPage: 0,
    };
  },
  async asyncData(app) {
    let res = await app.$api.getArticle({
      currentPage: 1,
      num: 10,
      isDynamicState: true,
    });
    let articleList = [...res.data];
    let totalPage = res.totalPage;
    let isShowToLoad;
    if (totalPage == 1 || totalPage == 0) {
      isShowToLoad = false;
    }
    return {
      articleList,
      totalPage,
      isShowToLoad,
    };
  },
  methods: {
    async getArticleInfo() {
      let res;
      if (this.activeName == "first") {
        res = await this.$api.getArticle({
          currentPage: this.currentPage,
          num: 10,
          isDynamicState: true,
        });
      } else if (this.activeName == "second") {
        res = await this.$api.getArticle({
          currentPage: this.currentPage,
          num: 10,
          path: "/category/cg-sketch/moeimo",
        });
      } else if (this.activeName == "third") {
        res = await this.$api.getArticle({
          currentPage: this.currentPage,
          num: 10,
          path: "/category/moehuivip/acgpack",
        });
      } else if (this.activeName == "fourth") {
        res = await this.$api.getArticle({
          currentPage: this.currentPage,
          num: 10,
          path: "/category/moehuivip/coursedown",
        });
      }
      this.articleList = [...this.articleList, ...res.data];
      this.totalPage = res.totalPage;
      if (this.currentPage == this.totalPage || res.totalPage == 0) {
        this.isShowToLoad = false;
      }
    },
    handleToLoad() {
      this.currentPage++;
      this.getArticleInfo();
    },
    handleClick(tab, event) {
      this.articleList = [];
      this.totalPage = 0;
      this.currentPage = 1;
      this.isShowToLoad = true;
      this.getArticleInfo();
    },
    //搜索
    handleSearch() {
      this.$router.push(`/search/${this.searchValue}`);
      // this.handleClose();
    },
  },
};
</script>
<style lang="less" scoped>
.app-search {
  background: #fff;
  padding: 0 20px;
  h2 {
    font-size: 22px;
    padding: 20px 0 10px;
    font-weight: bold;
  }
  div {
    display: flex;
    height: 34px;
    padding-bottom: 30px;
    input {
      flex: 1;
      border: 1px solid #eeeeee;
      outline: none;
      font-size: 14px;
      padding: 0 10px;
    }
    .el-button {
      color: #fff;
      padding: 10px 20px;
      background: #08c;
      border: 1px solid #08c;
      border-radius: 0;
      &:hover {
        background: #3361ea;
      }
    }
  }
}
/deep/.el-tabs {
  background: #fff;
  .el-tabs__nav-wrap {
    .el-tabs__nav-scroll {
      // padding: 0 20px;
      .el-tabs__nav {
        .el-tabs__item {
          font-size: 16px;
          color: #262626cc;
        }
      }
    }
    &::after {
      display: none;
    }
  }
}
.toLoad {
  width: 100%;
  background: #fff;
  padding-bottom: 40px;
  p {
    width: 266px;
    height: 36px;
    line-height: 36px;
    margin: 0 auto;
    font-size: 14px;
    text-align: center;
    color: #08c;
    border: 1px solid #08c;
    border-radius: 4px;
    box-sizing: border-box;
    cursor: pointer;
    &:hover {
      color: #fff;
      background: #3361ea;
      border: 1px solid #3361ea;
    }
  }
}
</style>